package com.mcvcm.bpaint.views
{
	import flash.display.Sprite;
	import flash.filters.DropShadowFilter;
	import com.mcvcm.bpaint.properties.CanvasProperty;
	
	/*
	** view class
	** drawing controled by tools
	*/
	public class Canvas extends Sprite
	{
		private var _mask:CanvasMask;
		private var _properties:CanvasProperties;
		
		public function set properties (properties:CanvasProperties):void
		{
			_properties = properties;
			draw();
			_mask.size(_properties);
		}
		
		public function get properties ():CanvasProperties
		{
			return _properties;
		}
		
		public function Canvas (properties:CanvasProperties):void
		{
			_properties = properties;
			_mask = new CanvasMask (properties);
			addChild(_mask);
			mask = _mask;
			var shadow:DropShadowFilter = new DropShadowFilter();
			filters.push(shadow);
			draw();
		}
		
		private function draw():void
		{
			graphics.clear();
			graphics.beginFill(_properties.color);
			graphics.drawRect(0, 0, _properties.width, _properties.height);
			graphics.endFill();
		}
	}
}
	/*
	** this class is supposed to be used by Canvas only
	** it mask the canvas, so that no bubbles outside the virtual boundry 
	** will not be shown.
	** and any click events that happens outside the masked area of canvas
	** won't affect the drawing process at all.
	*/
	import flash.display.Sprite;
	import flash.display.Shape;
	import com.mcvcm.bpaint.properties.CanvasProperties;

	class CanvasMask extends Shape
	{
		public function CanvasMask (canvasProperties:CanvasProperties):void
		{
			size(canvasProperties);
		}
		
		private function draw (width:uint, height:uint):void
		{
			with (graphics)
			{
				clear();
				beginFill(0xffffff);
				drawRect(0, 0, width, height);
				endFill();				
			}
		}
		
		public function size (canvasProperties:CanvasProperties):void
		{
			draw (canvasProperties.width, canvasProperties.height);
		}
	}